//
//  AddTraineeViewController.m
//  TraineeManagementSystem
//
//  Created by Dhanashree Bodas on 28/01/15.
//  Copyright (c) 2015 Dhanashree Bodas. All rights reserved.
//

#import "AddTraineeViewController.h"
#import "TraineeTable.h"
#import "TraineeViewController.h"


@interface AddTraineeViewController ()

@end

@implementation AddTraineeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)passwordEntered:(id)sender {
    
    [self resignFirstResponder];
}

- (IBAction)fnameEntered:(id)sender {
    
    [self resignFirstResponder];
}

- (IBAction)lnameEntered:(id)sender {
    
    [self resignFirstResponder];
}

- (IBAction)emailEntered:(id)sender {
    
    [self resignFirstResponder];
}



- (IBAction)cancelPressed:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)addPressed:(id)sender {
    
    TraineeTable *t=[[TraineeTable alloc] init];
    
    if( [self.fname.text isEqualToString:@""] | [self.lname.text isEqualToString:@""] | [self.email.text isEqualToString:@""] | [self.password.text isEqualToString:@""])
    {
        
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Validation" message:@"Fields cannot be empty" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        
        [alert show];
        
        
    }
    else
    {
        
        int i=[t addTrainee:self.fname.text andLname:self.lname.text andEmail:self.email.text andPassword:self.password.text];
    
        if(i==1)
        {
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Add Trainee" message:@"Trainee added successfully" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
      
            [alert show];
            [self dismissViewControllerAnimated:YES completion:nil];
        
        }
        else
            NSLog(@"Errorr!!!!!!!!!!");
     }
}

@end
